##parameters=assessmentIdentity
from StringIO import StringIO

out = StringIO()

ass = context.knowledgeengine_assessmentstorageservice


done = []

def buildMap( aid ):

    assessment = ass.loadAssessment( aid )
    
    if aid in done: return
    
    done.append( aid )

    linksTo   = ass.getLinksToAssessment( aid );
    linksFrom = ass.getLinksFromAssessment( aid );

    for link in linksTo:        
        linkObject = ass.loadAssessment( link )
        
        print >> out, '"%s" -> "%s";' % ( linkObject.getName(), assessment.getName() )        
        
        buildMap( link )
        
    
    for link in linksFrom:
        buildMap( link )
    
    
print >> out, """digraph assessments { size="10,10"; """    
buildMap( assessmentIdentity )
print >> out, "}"    

context.REQUEST.RESPONSE.setHeader('content-disposition', 'attachment; filename=%s.dot' % assessmentIdentity)

#return printed
return out.getvalue()